package com.itheima.service.impl;

import com.itheima.dao.AddressDao;
import com.itheima.domain.Address;
import com.itheima.service.AddressService;
import com.itheima.util.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AddressServiceImpl implements AddressService {
    @Override
    public List<Address> findByUid(int uid) {
        //1.创建代理对象
        SqlSession sqlSession = MyBatisUtils.openSession();
        AddressDao addressDao=sqlSession.getMapper(AddressDao.class);
        //调用Dao
        List<Address>addressList=addressDao.findByUid(uid);
        //关闭会话
        MyBatisUtils.close(sqlSession);
        return addressList;
    }

    @Override
    public void save(Address param) {
           //1.创建代理对象
        SqlSession sqlSession = MyBatisUtils.openSession();
        AddressDao addressDao = sqlSession.getMapper(AddressDao.class);
        //2.调用Dao
        addressDao.save(param);
        //3.关闭会话
        MyBatisUtils.close(sqlSession);
    }
}
